#!/usr/bin/env python
# encoding: utf-8
'''
@author: cunyu
@contact: 1372307989@qq.com
@software: Pycharm
@file: ciyun.py
@time: 2018/1/25 11:08
@desc:
'''
from wordcloud import WordCloud
import jieba
import numpy
import PIL.Image as Img
import os

# stopword = {"然后": 0, "这些": 0, "那些": 0}
cur_path = os.path.dirname(__file__)


# 中文转换
def chinese_jieba(text):
    wordlist_jieba = jieba.cut(text)
    text_jieba = ' '.join(wordlist_jieba)
    return text_jieba


with open(os.path.join(cur_path, 'love_all.txt'), 'r') as fp:
    text = fp.read()
    text = chinese_jieba(text)
    mask_pic = numpy.array(Img.open(os.path.join(cur_path+"/man.png")))
    # print(text)
    # background_color 背景颜色   max_words  关键词个数   max_font_size 限制字体大小  stopwords  去除噪声词 mask 设置图片
    wordcloud = WordCloud(font_path='FZLTXIHK.TTF', mask=mask_pic).generate(text)
    img = wordcloud.to_image()
    img.show()
